﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Lucene.Net.Search;
using Lucene.Net.QueryParsers;
using Lucene.Net.Documents;
using Lucene.Net.Analysis;
using Lucene.Net.Index;
using Lucene.Net.Store;
using Lucene.Net.Analysis.Standard;
//using htmlParser = Winista.Text.HtmlParser;
//using Winista.Text.HtmlParser.Visitors;
//using Winista.Text.HtmlParser.Util;
//using Winista.Text.HtmlParser.Filters;
//using Winista.Text.HtmlParser.Tags;
//using Winista.Text.HtmlParser;
//using Winista.Text.HtmlParser.Lex;
using System.Text.RegularExpressions;
using System.Text;
//using OgilvyOne.UKNOW.Entity;
using System.Configuration;


public partial class UKNOW_member_Search : System.Web.UI.Page
{
    public string searchKey;
    public string searchCount;
    public string searchResult;
  
    protected void Page_Load(object sender, EventArgs e)
    {
        //接受外部页面参数，调用检索
        //|| (!String.IsNullOrEmpty(this.Request["hidesearchKey"]))
        if (!IsPostBack)
        {
            if (!String.IsNullOrEmpty(this.Request["value"]))
            {
                string value = HttpUtility.UrlDecode(this.Request["value"]);
                SearchByParagraph(value);
            }
            if (!string.IsNullOrEmpty(this.Request.Params["hideSearchValue"]))
            {
               
               string value1 = HttpUtility.UrlDecode(this.Request.Params["hideSearchValue"]);
             
                SearchByParagraph(value1);
            }

        }
    }
    
    protected void lkbSearch_Click(object sender, EventArgs e)
    {
        
        SearchByParagraph(SearchLeft.Text);
    }
    /// <summary>
    /// 搜索
    /// </summary>
  
    public  void SearchByParagraph(string searchValue)
    {
        //string isCreateIndexFiles = ConfigurationSettings.AppSettings["IsCreateIndexFiles"]; 
        //SearchEntity searchEntity = new SearchEntity();
        //searchEntity.FilePath = GetFilePath();
        //searchEntity.IndexPath = GetIndexPath();
        //searchEntity.IsCreate = true;
        //SearchTop.Text = searchValue;
        //if (!string.IsNullOrEmpty(searchValue))
        //{
        //    searchEntity.SearchKey = searchValue.Trim();
           
        //}
       

        //if (string.IsNullOrEmpty(searchEntity.SearchKey))
        //{
        //    if (string.IsNullOrEmpty(searchEntity.SearchResult))
        //    {
        //        if ((string)ViewState["result"] != null)
        //        {
        //            searchResult = (string)ViewState["result"];
                    
        //        }
        //        if ((string)ViewState["searchcount"] != null)
        //        {
        //            searchCount = (string)ViewState["searchcount"];

        //        }
               
        //    }
        //    ScriptManager.RegisterClientScriptBlock(Page, GetType(), "", "alert('请输入搜索关键字')", true);
           
        //    return;
        //}
        //if (isCreateIndexFiles == "1")
        //{
        //    searchEntity.AddDocument();
        //    searchEntity.BuildIndexFile();
        //}
        
        //searchEntity.QueryByParagraph();
        //searchKey = searchEntity.SearchKey;
        //searchCount = searchEntity.ResultCount;

        //ViewState["searchcount"] = searchEntity.ResultCount;
        //searchResult = searchEntity.SearchResult;
        //ViewState["result"] = searchEntity.SearchResult;
        //if (hideSearchType.Value == "left")
        //{
        //    SearchLeft.Text = searchValue;
        //}
        //else
        //{
        //    SearchTop.Text = searchValue;
        //}
    }


  
    /// <summary>
    /// 获取文件路径
    /// </summary>
    /// <returns></returns>
    private string GetFilePath()
    {
        string path_file = ConfigurationSettings.AppSettings["CnPathFile"];
        return GetRootPath() +path_file;
    }
    
    
    /// <summary>
    /// 获取索引文件路径
    /// </summary>
    /// <returns></returns>
    private string GetIndexPath()
    {
        string indexPath = ConfigurationSettings.AppSettings["CnPathIndex"]; ;
        return GetRootPath() + indexPath;
    }


    /// <summary>
    /// 获取根目录
    /// </summary>
    /// <returns></returns>
    private string GetRootPath()
    {
        return Server.MapPath("~");
    }

   

    protected void lkbSearchTop_Click(object sender, EventArgs e)
    {
        SearchLeft.Text = "";
        SearchByParagraph(SearchTop.Text);
    }
}
